﻿using System;
using System.Windows.Forms;

namespace Sorteo.UI
{
    public partial class BaseForm : Form
    {
        #region Constructors

        public BaseForm()
        {
            InitializeComponent();
        }

        #endregion

        #region Methods: Public

        public void ShowError(string description)
        {
            MessageBox.Show(description, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public bool ShowQuestion(string description)
        {
            return (MessageBox.Show(description, Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
        }

        public void ShowConfirmation(string description)
        {
            MessageBox.Show(description, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        protected static void ClearControls(Control.ControlCollection controls)
        {
            foreach (Control ctr in controls)
            {
                if (ctr.GetType().ToString().IndexOf("TextBox") > -1 || ctr.GetType().ToString().IndexOf("NumBox") > -1)
                    ctr.Text = "";

                else if (ctr.GetType().ToString().IndexOf("Label") > -1)
                {
                    if (ctr.Tag != null)
                        ctr.Text = ctr.Tag.ToString();
                }
                else if (ctr.GetType().ToString().IndexOf("ComboBox") > -1)
                {
                    var combo = (ComboBox)ctr;
                    combo.SelectedIndex = -1;
                    combo.SelectedIndex = -1;
                }
                else if (ctr.GetType().ToString().IndexOf("DateTimePicker") > -1)
                    ((DateTimePicker)ctr).Value = DateTime.Now;

                else if (ctr.GetType().ToString().IndexOf("CheckBox") > -1 || ctr.GetType().ToString().IndexOf("RadioButton") > -1)
                    ((CheckBox)ctr).Checked = false;

                if (ctr.Controls.Count > 0)
                    ClearControls(ctr.Controls);
            }
        }

        #endregion
    }
}
